﻿using Abp.Domain.Entities;
using Dapper;
using Mall.DomainModel.Dto.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Mall.Service.Dto.Query
{
    public abstract class QueryObject<Entity> : IQueryObject<Entity>
    {
        private SortOrder _sortOrder;

        private Expression<Func<Entity, object>> _orderField;

        public int Count { get; set; } = 10;


        public Expression<Func<Entity, object>> OrderField => _orderField;

        public SortOrder OrderSort => _sortOrder;

        public abstract List<Expression<Func<Entity, bool>>> QueryExpression { get; }

        public virtual Dictionary<string, DynamicParameters> QuerySql { get; }

        public int Skip { get; set; }

        public void OrderBy(Expression<Func<Entity, object>> order)
        {
            _sortOrder = SortOrder.ASC;
            _orderField = order;
        }

        public void OrderByDesc(Expression<Func<Entity, object>> order)
        {
            _sortOrder = SortOrder.DESC;
            _orderField = order;
        }
    }
}
